package org.dromara.wms.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.web.core.BaseService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.wms.domain.vo.WmsOrderTypeVo;
import org.dromara.wms.domain.bo.WmsOrderTypeBo;
import org.dromara.wms.service.impl.WmsOrderTypeServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 仓储作业类别表
 *
 * @author wenrui
 * @date 2024-03-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/orderType")
public class WmsOrderTypeController extends BaseService {

    private final WmsOrderTypeServiceImpl wmsOrderTypeService;

    /**
     * 查询仓储作业类别表列表
     */
    @SaCheckPermission("wms:orderType:list")
    @GetMapping("/list")
    public TableDataInfo<WmsOrderTypeVo> list(WmsOrderTypeBo bo, PageQuery pageQuery) {
        return wmsOrderTypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出仓储作业类别表列表
     */
    @SaCheckPermission("wms:orderType:export")
    @Log(title = "仓储作业类别表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WmsOrderTypeBo bo, HttpServletResponse response) {
        List<WmsOrderTypeVo> list = wmsOrderTypeService.queryList(bo);
        ExcelUtil.exportExcel(list, "仓储作业类别表", WmsOrderTypeVo.class, response);
    }

    /**
     * 获取仓储作业类别表详细信息
     *
     * @param typeId 主键
     */
    @SaCheckPermission("wms:orderType:query")
    @GetMapping("/{typeId}")
    public R<WmsOrderTypeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long typeId) {
        return R.ok(wmsOrderTypeService.queryById(typeId));
    }

    /**
     * 新增仓储作业类别表
     */
    @SaCheckPermission("wms:orderType:add")
    @Log(title = "仓储作业类别表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsOrderTypeBo bo) {
        return toAjax(wmsOrderTypeService.insertByBo(bo));
    }

    /**
     * 修改仓储作业类别表
     */
    @SaCheckPermission("wms:orderType:edit")
    @Log(title = "仓储作业类别表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsOrderTypeBo bo) {
        return toAjax(wmsOrderTypeService.updateByBo(bo));
    }

    /**
     * 删除仓储作业类别表
     *
     * @param typeIds 主键串
     */
    @SaCheckPermission("wms:orderType:remove")
    @Log(title = "仓储作业类别表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{typeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] typeIds) {
        return toAjax(wmsOrderTypeService.deleteWithValidByIds(List.of(typeIds), true));
    }
}
